/**
 * Copyright &copy; 2016-2017 <a href="https://www.lczyfz.com">联创智云</a> All rights reserved.
 */
package com.lczyfz.campusinfo.modules.jobmesmanage.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lczyfz.campusinfo.common.utils.Const;
import com.lczyfz.campusinfo.modules.jobmesmanage.service.InetAddressService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.lczyfz.campusinfo.common.config.Global;
import com.lczyfz.campusinfo.common.persistence.Page;
import com.lczyfz.campusinfo.common.web.BaseController;
import com.lczyfz.campusinfo.common.utils.StringUtils;
import com.lczyfz.campusinfo.modules.jobmesmanage.entity.SchoStutype;
import com.lczyfz.campusinfo.modules.jobmesmanage.service.SchoStutypeService;

/**
 * 勤工业务Controller
 * @author zms
 * @version 2018-03-23
 */
@Controller
@RequestMapping(value = "${adminPath}/jobmesmanage/schoStutype")
public class SchoStutypeController extends BaseController {

	@Autowired
	private SchoStutypeService schoStutypeService;
	private InetAddressService inetAddressService = new InetAddressService();
	@ModelAttribute
	public SchoStutype get(@RequestParam(required=false) String id) {
		SchoStutype entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = schoStutypeService.get(id);
		}
		if (entity == null){
			entity = new SchoStutype();
		}
		return entity;
	}
	
	@RequiresPermissions("jobmesmanage:schoStutype:view")
	@RequestMapping(value = {"list", ""})
	public String list(SchoStutype schoStutype, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<SchoStutype> page = schoStutypeService.findPage(new Page<SchoStutype>(request, response), schoStutype); 
		model.addAttribute("page", page);
		return "modules/jobmesmanage/schoStutypeList";
	}

	@RequiresPermissions("jobmesmanage:schoStutype:view")
	@RequestMapping(value = "form")
	public String form(SchoStutype schoStutype, Model model) {
		model.addAttribute("schoStutype", schoStutype);
		return "modules/jobmesmanage/schoStutypeForm";
	}

	@RequiresPermissions("jobmesmanage:schoStutype:edit")
	@RequestMapping(value = "save")
	public String save(SchoStutype schoStutype, HttpServletRequest request, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, schoStutype)){
			return form(schoStutype, model);
		}
		if (StringUtils.isNotBlank(schoStutype.getRedImg())){
			schoStutype.setRedImg(Const.getinetAddressService(schoStutype.getRedImg(),request));
		}
		schoStutypeService.save(schoStutype);
		addMessage(redirectAttributes, "保存勤工业务成功");
		return "redirect:"+Global.getAdminPath()+"/jobmesmanage/schoStutype/?repage";
	}
	
	@RequiresPermissions("jobmesmanage:schoStutype:edit")
	@RequestMapping(value = "delete")
	public String delete(SchoStutype schoStutype, RedirectAttributes redirectAttributes) {
		schoStutypeService.delete(schoStutype);
		addMessage(redirectAttributes, "删除勤工业务成功");
		return "redirect:"+Global.getAdminPath()+"/jobmesmanage/schoStutype/?repage";
	}

}